package com.ysstech.kettle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ysstech.common.entity.PageBean;
import com.ysstech.kettle.entity.JobParam;
import com.ysstech.kettle.mapper.JobParamMapper;
import com.ysstech.kettle.service.JobParamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * kettle参数信息表 服务实现类
 * </p>
 *
 * @author lishuangliang
 * @since 2022-10-17
 */
@Service
public class JobParamServiceImpl extends ServiceImpl<JobParamMapper, JobParam> implements JobParamService {

    /**
     * 查询参数信息表列表信息
     *
     * @param jobParam
     * @param pageBean
     * @return
     * @throws Exception
     */
    public PageBean<JobParam> queryAllJobParam(JobParam jobParam, PageBean pageBean) throws Exception {
        QueryWrapper<JobParam> wrapper = this.getQueryWrapper(jobParam);
        IPage pageBalance = this.page(new Page<>(pageBean.getPageNum(), pageBean.getPageSize()), wrapper);
        this.switchedListCategory(pageBalance.getRecords());
        return new PageBean<>(pageBalance);
    }


    /**
     * 类型，机构等中文的转换
     *
     * @param list
     * @return
     * @throws Exception
     */
    public List<JobParam> switchedListCategory(List<JobParam> list) throws Exception {
        for (JobParam jobParam : list) {
            if (null == jobParam) {
                continue;
            }
        }
        return list;
    }

    /**
     * 查询条件
     *
     * @param jobParam
     * @return
     * @throws Exception
     */
    private QueryWrapper<JobParam> getQueryWrapper(JobParam jobParam) throws Exception {
        QueryWrapper<JobParam> wrapper = new QueryWrapper<>();
        if (null == jobParam) {
            return wrapper;
        }
        if (StringUtils.isNotBlank(jobParam.getKeyName())) {
            wrapper.like("KEY_NAME", jobParam.getKeyName());
        }
        if (StringUtils.isNotBlank(jobParam.getChineseName())) {
            wrapper.like("CHINESE_NAME", jobParam.getChineseName());
        }
        wrapper.orderByAsc("SEQUENCE");
        return wrapper;
    }
}
